# Maintainer: Andreas 'Segaja' Schleifer <segaja at archlinux dot org>

_gemname='marcel'
pkgname="ruby-${_gemname}"
pkgver=1.0.2
pkgrel=1
pkgdesc='Simple mime type detection using magic numbers, filenames, and extensions'
arch=('any')
url='https://github.com/rails/marcel'
license=('Apache' 'MIT')
options=(!emptydirs)
depends=('ruby')
makedepends=('ruby-bundler' 'ruby-rake')
checkdepends=('ruby-minitest' 'ruby-rack')
source=("${url}/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz")
sha512sums=('cd159545b246dcbd26ca07ac69e36ff13a965ac0e99ebd040c53b6a92f8ec8fd65786783c9a173d669fe6b32340a23d72c83c483011eec2e1097bdea73810ed6')

prepare() {
  cd "${_gemname}-${pkgver}"

  # update gemspec/Gemfile to allow newer version of the dependencies
  sed --in-place --regexp-extended 's|~>|>=|g' "${_gemname}.gemspec"

  # we dont need debuggers for testing
  sed --in-place --regexp-extend '/byebug/d' "${_gemname}.gemspec"  test/test_helper.rb
}

build() {
  cd "${_gemname}-${pkgver}"

  rake build
}

check() {
  cd "${_gemname}-${pkgver}"

  rake test
}

package() {
  cd "${_gemname}-${pkgver}"

  local _gemdir="$(gem env gemdir)"

  gem install --ignore-dependencies --no-user-install -i "${pkgdir}/${_gemdir}" -n "${pkgdir}/usr/bin" "pkg/${_gemname}-${pkgver}.gem"

  rm "${pkgdir}/${_gemdir}/cache/${_gemname}-${pkgver}.gem"

  install -Dm 644 APACHE-LICENSE MIT-LICENSE --target-directory "${pkgdir}/usr/share/licenses/${pkgname}"
  install -Dm 644 README.md --target-directory "${pkgdir}/usr/share/doc/${pkgname}"
}
